package cn.itcast.order.mq;


import cn.itcast.hmall.pojo.order.Order;
import cn.itcast.order.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;


@Slf4j
@Configuration
public class Mq {
    @Autowired
    OrderMapper orderMapper;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "dl.ttl.queue", durable = "true"),
            exchange = @Exchange(name = "dl.ttl.direct"),
            key = "ttl"
    ))
    public void listenDlQueue(Long orderId) {
        Order order = orderMapper.selectById(orderId);
        if (order.getStatus()==1){
            int i = orderMapper.deleteById(orderId);
            if (i!=0){
                log.info("删除订单成功");
            }
        }

    }


}
